package com.example.demo.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    //返回状态码
    private String code;
    //返回描述 001 成功 401 失败
    private String msg;
    //返回数据
    private Object data;

    public static Result ok() {
        Result result = new Result();
        result.setCode("001");
        result.setMsg("请求成功");
        return result;
    }

    public static Result ok(String msg) {
        Result result = new Result();

        result.setCode("001");
        result.setMsg(msg);
        return result;
    }

    public static Result ok(Object data) {
        Result result = new Result();
        result.setCode("001");
        result.setMsg("操作成功");
        result.setData(data);
        return result;
    }

    public static Result ok(String msg, Object data) {
        Result result = new Result();
        result.setCode("001");
        result.setMsg(msg);
        result.setData(data);
        return result;
    }


    public static Result error() {
        Result result = new Result();
        result.setCode("401");
        result.setMsg("请求失败");
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setCode("401");
        result.setMsg(msg);
        return result;
    }


}
